<?php
/**
 * Language
 * 
 * 作者:  姚刚 (yaogang@the9sense.com)
 * 创建时间: 2011-02-24 00:23:33
 * 修改记录: 
 * 
 * $Id: Language.php 3 2011-03-08 14:47:40Z coosuu@gmail.com $
 */

class Language {

    private static $_loaded = array();

    public static function get() {

        $package = 'zh_cn';
        if (defined('LAN')) {
            $package = LAN;
        }

        $file = APP_PATH . '/language/' . $package . '.php';
        if (!array_key_exists($package, self::$_loaded)) {
            if (!file_exists($file)) {
                throw new Language_Exception('Cannot load language package:' . $package);
            }

            require_once $file;
            self::$_loaded[$package] = $lan;
        }

        $argsNum = func_num_args();
        if (!$argsNum) {
            return self::$_loaded[$package];
        }

        $args = func_get_args();
        $key = array_shift($args);
        if (array_key_exists($key, self::$_loaded[$package])) {
            return vsprintf(self::$_loaded[$package][$key], $args);
        }

        return null;
    }

}
